home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-06 | 4.1 KB | 166 lines | [TEXT/GEOL] |
- Item 5489464 5-Oct-89 19:13
-
- From: V0230 Trace, Laurence Kirsh,VAR
-
- To: D2652 Strategic Planning Sys, D Bell,PRT
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: RE WindowMenu Recipe
-
- Don,
-
- Here, for what it's worth, is my recipe for a Windows menu. Note: this comes
- from a MacApp 1.1.1 application, so some adjustment may be needed for 2.0ß9.
-
- ======> .r file, add a cmnu declaration [5 is the ID I used in this case]
- resource 'cmnu' (5) {
- 5,
- textMenuProc,
- allEnabled,
- enabled,
- "Windows",
- {
- }
- };
-
- ======> "global" declarations:
- Const
- kWindowMenuID = 5; {window menu resource ID}
-
- {$S ARes}
- Procedure AddToWindowMenu (AtTop: Boolean; Name: Str255);
- {add the name (usually a window name) to the Window menu.
- If AtTop is True, the name is inserted at the top of the
- menu, otherwise at the bottom.}
-
- Var
- Menu: MenuHandle;
- Item: Integer;
-
- Begin
- Menu := GetMHandle (kWindowMenuID);
- If AtTop
- Then Item := 0 {insert before first}
- Else Item := CountMItems(Menu)+1; {insert at bottom}
- InsMenuItem (Menu, 'A', Item); {just add a dummy, because this tries to do
- meta-characters,}
- If Item = 0 Then Item := 1;
- SetItem (Menu, Item, Name) {and this one does not}
- End; {AddToWindowMenu}
-
- {$S ARes}
- Procedure DeleteFromWindowMenu (Name: Str255);
- {remove the menu item with name Name from the Window menu.
- If it's not there, do nothing}
-
- Var
- Menu: MenuHandle;
- Last: Integer;
- Item: Integer;
- ItemName: Str255;
-
- Begin
- Menu := GetMHandle (kWindowMenuID);
- Last := CountMItems (Menu);
-
- Item := 1;
- While Item <= Last Do Begin
- GetItem (Menu, Item, ItemName);
- If ItemName = Name Then Begin
- DelMenuItem (Menu, Item);
- Item := Last {exit loop}
- End;
- Item := Succ(Item)
- End
- End; {DeleteFromWindowMenu}
-
-
- ======> in your window objects, override Open and Close:
- {$S AOpen}
- Procedure TAnyWindowObject.Open; OVERRIDE;
- Begin
- If Not fInOpenWindow Then
- AddToWindowMenu (True, WindowPeek(fWmgrWindow)^.TitleHandle^^);
- INHERITED Open
- End; {TAnyWindowObject.Open}
-
- {$S AClose}
- Procedure TAnyWindowObject.Close; OVERRIDE;
- Begin
- DeleteFromWindowMenu (WindowPeek(fWMgrWindow)^.TitleHandle^^);
- INHERITED Close
- End; {TAnyWindowObject.Close}
-
-
- ======> in your application, override DoSetUpMenus and DoMenuCommand:
- {$S ARes}
- Procedure TYourApplication.DoSetUpMenus; OVERRIDE;
-
- Var
- I: Integer;{to enable Window menu items}
- Menu: MenuHandle;
-
- Begin
- INHERITED DoSetUpMenus;
-
- <<<< other enables >>>>
-
- {enable the window names in the windows menu}
- Menu := GetMHandle (kWindowMenuID);
- If Menu <> Nil Then
- For I := 1 to CountMItems (Menu) Do
- EnableItem (Menu, I);
- End; {TYourApplication.DoSetUpMenus}
-
- {$S ASelCommand}
- Function TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber): TCommand;
- OVERRIDE;
- {Capture all CmdNumbers for use with Help window.
- Open Help window if they ask for it, otherwise call INHERITED.}
-
- Var
- Menu: Integer; {menu belonging to aCmdNumber}
- Item: Integer; {item belonging to aCmdNumber}
- ItemName: Str255; {name of Item}
- Wind: WindowPtr; {used to search window list for ItemName}
- aName: Str255; {name of Wind}
-
- Begin
- DoMenuCommand := gNoChanges;
-
- {First check to see if the user selected a window name from the
- Windows menu, because the handling of this is non-standard.}
-
- CmdToMenuItem (aCmdNumber, Menu, Item);
-
- If Menu = kWindowMenuID
- Then Begin
- GetItem (GetMHandle(Menu), Item, ItemName);
-
- {look through the window list}
- Wind := FrontWindow;
- While Wind <> Nil Do Begin
- GetWTitle (Wind, aName);
- If aName <> ItemName
- Then Wind := WindowPtr(WindowPeek(Wind)^.NextWindow)
- Else Begin
- SelectWindow (Wind);
- Wind := Nil {exit loop}
- End
- End
-
- End {window menu selection}
-
- Else If <<<< check for other command numbers...... >>>>
-
- Else DoMenuCommand := INHERITED DoMenuCommand (aCmdNumber)
-
- End; {TYourApplication.DoMenuCommand}
-
- ======
- I'd appreciate any changes/improvements that anyone has to suggest.
-
- John MacVeigh, Trace Inc.
-
-